﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace Epam.PeopleModel
{
    class DateFormatAttribute : ValidationAttribute, IClientValidatable, IMetadataAware
    {
        public override bool IsValid(object value)
        {
            return value is DateTime;
        }

        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
           yield return new ModelClientValidationRule
                            {
                                ErrorMessage = ErrorMessage,
                                ValidationType = "formatdatevalidate"
                            };
        }

        public void OnMetadataCreated(ModelMetadata metadata)
        {
            metadata.DataTypeName = "Date";
        }
    }
}
